home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cgraphix / kdrawsqr.c < prev    next >
Text File  |  1986-05-27  |  2KB  |  107 lines

  1. /* «RM120»«PL99999»«TS4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76» */
  2. #include    <stdio.h>
  3. #define    EXTERN    extern
  4. #include    <typedef.h>
  5.  
  6. static void DSC1(x1, x2, y)
  7. int        x1, x2, y;
  8. {
  9.     if (clip(&x1, &y, &x2, &y)) {
  10.         if (LineStyleGlb == 0) {
  11.             DrawStraight(x1, x2, y);
  12.         }
  13.         else {
  14.             DrawLine((double)x1, (double)y, (double)x2, (double)y);
  15.         }
  16.     }
  17. }
  18.  
  19.  
  20. void DrawSquareC(x1, y1, x2, y2, fill)
  21. int        x1, y1, x2, y2, fill;
  22. {
  23.     int        i;
  24.  
  25.     if (!fill) {
  26.         DSC1(x1, x2, y1);
  27.         DrawLineClipped(x2, y1, x2, y2);
  28.         DSC1(x1, x2, y2);
  29.         DrawLineClipped(x1, y2, x1, y1);
  30.     }
  31.     else {
  32.         for (i = y2; i <= y1; i++)
  33.             DSC1(x1, x2, i);
  34.     }
  35. }
  36.  
  37.  
  38. static void DS(x1, x2, y)
  39. int        x1, x2, y;
  40. {
  41.  
  42.     if (LineStyleGlb == 0) {
  43.         DrawStraight(x1, x2, y);
  44.     }
  45.     else {
  46.         DrawLineDirect(x1, y, x2, y);
  47.     }
  48. }
  49.  
  50.  
  51. static void DSC(x1, x2, y)
  52. int        x1, x2, y;
  53. {
  54.     if (clip(&x1, &y, &x2, &y))
  55.         DS(x1, x2, y);
  56. }
  57.  
  58.  
  59. void DrawSqr(x1, y1, x2, y2, fill)
  60. int        x1, y1, x2, y2, fill;
  61. {
  62.     int        i;
  63.  
  64.     if (!fill) {
  65.         DS(x1, x2, y1);
  66.         DrawLineDirect(x2, y1, x2, y2);
  67.         DS(x1, x2, y2);
  68.         DrawLineDirect(x1, y2, x1, y1);
  69.     }
  70.     else {
  71.         for (i = y1; i <= y2; i++)
  72.             DS(x1, x2, i);
  73.     }
  74. }
  75.  
  76.  
  77. void DrawSquare(X1, Y1, X2, Y2, fill)
  78. double    X1, Y1, X2, Y2;
  79. int        fill;
  80. {
  81.     int        i, x1loc, y1loc, x2loc, y2loc;
  82.     int        DirectModeLoc;
  83.  
  84.     if (DirectModeGlb) {
  85.         DrawSqr((int)(X1),(int)(Y1),(int)(X2),(int)(Y2),fill);
  86.     }
  87.     else {
  88.         DirectModeLoc = DirectModeGlb;
  89.         DirectModeGlb = TRUE;
  90.         x1loc = WindowX(X1);
  91.         y1loc = WindowY(Y1);
  92.         x2loc = WindowX(X2);
  93.         y2loc = WindowY(Y2);
  94.         if (!fill) {
  95.             DSC(x1loc, x2loc, y1loc);
  96.             DrawLineClipped(x2loc, y1loc, x2loc, y2loc);
  97.             DSC(x1loc, x2loc, y2loc);
  98.             DrawLineClipped(x1loc, y2loc, x1loc, y1loc);
  99.         }
  100.         else
  101.             for (i = y1loc; i <= y2loc; i++)
  102.                 DSC(x1loc,x2loc,i);
  103.         DirectModeGlb = DirectModeLoc;
  104.     }
  105. }
  106.  
  107.